package com.cloudmusic.api.utils;

import com.cloudmusic.api.entity.Admin;

import java.util.Date;
import java.util.HashMap;

/**
 * @ description:
 * @ date:      2020/10/9
 * @ time:      10:25
 * @ author:    Zhang wei
 * @ since:     1.0.0
 */
public class AdminTokenUtil {
    private static final HashMap<String, Integer> tokenMap = new HashMap<>();

    public static void addToken(Integer id, String token) {
        AdminTokenUtil.tokenMap.put(token, id);
    }

    public static void removeToken(String token) {
        AdminTokenUtil.tokenMap.remove(token);
    }

    public static Integer getAdminId(String token) {
        return AdminTokenUtil.tokenMap.get(token);
    }

    public static String getToken(Admin admin) {
        return admin.getAdminId() + "_" + new Date();
    }
}
